//初始化
$(document).ready(function(){
	geteData(1);
});

//分页栏
function Pager(That_Page,Last_Page){
	var pager=$('#pager');
	pager.html("");
	if((That_Page-1)>0){
		pager.append('<li><span>首页</span></li>');
		pager.append('<li class="prev" ><span>上一页</span></li>');
		pager.append('<li>'+parseInt(That_Page-1)+'</li>');
	}else{
		pager.append('<li class="none"><span>首页</span></li>');
		pager.append('<li class="none"><span>上一页</span></li>');
	}
	pager.append('<li class="act">'+That_Page+'</li>');
	if((That_Page+1)<=Last_Page){
		pager.append('<li>'+ parseFloat(That_Page+1) +'</li>');
		pager.append('<li class="next go"><span>下一页</span></li>');
		pager.append('<li class="go" data-last="'+Last_Page+'"><span>尾页</span></li>');
	}else{
		pager.append('<li class="none"><span>下一页</span></li>');
		pager.append('<li class="none"><span>尾页</span></li>');
	}
	pager.append('<li class="All_page" disabled="disabled"><span>共'+Last_Page+'页</span></li>');
}

//点击分页栏
$('#pager').on('click','#pager>li',function(event){
	var This=$(this),pageNum;
	if(This.hasClass('act')||This.hasClass('All_page')||This.hasClass('none')){
		return true;
	}else{
		if(This.children().length!=0){
			if(This.hasClass('go')){//判断 此页 的  右边还是左边
				if(This.hasClass('next')){
					pageNum=parseFloat(parseInt(This.siblings('.act').text())+1);
				}else{
					pageNum=parseInt(This.attr('data-last'));
				}
			}else {
				if (This.hasClass('prev')) {
					pageNum = parseFloat(parseInt(This.siblings('.act').text())-1);
				} else {
					pageNum = 1;
				}
			}
			geteData(pageNum);
			$(document).scrollTop(0);
		}else{
			pageNum = parseFloat(This.text());
			geteData(pageNum);
			$(document).scrollTop(0);
		}
	}
});

function geteData(pageNum){
	var pageSize = 10;
	$.getJSON(path+'/pagehelperShow/show.do?pageNum='+pageNum+'&pageSize='+pageSize, function(data) {
		$('#show_body').html("");
		showRule(data);
	});
}

function showRule(data){
	for(var i=0;i<data.list.length;i++){
		showInfo(data.list[i]);
	}
	Pager(data.pageNum,data.pages);
}

function showInfo(userinfo){
	var info_div = $('#show_body');
	var info_tr = $('<tr/>');
	info_tr.append('<td>'+userinfo.userId+'</td>');
	info_tr.append('<td>'+userinfo.username+'</td>');
	info_tr.append('<td>'+userinfo.password+'</td>');
	info_div.append(info_tr);
}